package com.bawei.module_service.ui.polling

import android.os.Bundle
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.bawei.lib_common.Router
import com.bawei.lib_common.base.BaseActivity
import com.bawei.lib_common.base.BaseViewModel
import com.bawei.lib_common.base.state.Empty
import com.bawei.lib_common.base.state.Failed
import com.bawei.lib_common.base.state.Loading
import com.bawei.lib_common.base.state.Success
import com.bawei.lib_common.observeWithLifecycle
import com.bawei.lib_common.utils.ToastUtils
import com.bawei.module_service.R
import com.bawei.module_service.adapter.PollingAdapter
import com.bawei.module_service.databinding.ActivityPolling2Binding
import com.bawei.module_service.http.ServiceViewModel
import com.bumptech.glide.Glide
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = Router.POLLING_PAGE)
class PollingActivity2 : BaseActivity<BaseViewModel, ActivityPolling2Binding>() {
    override val mLayoutResId: Int
        get() = R.layout.activity_polling2

    val mAdapter : PollingAdapter by lazy { PollingAdapter() }
    private val mViewModel: ServiceViewModel by viewModels()
    override fun initView() {

        mBinding.maintainToobar.title1.text = "点位管理"
        mBinding.maintainToobar.title1.visibility = View.VISIBLE
        mBinding.maintainToobar.title.visibility= View.GONE
        Glide.with(this)
            .load(com.bawei.lib_common.R.drawable.more)
            .into(mBinding.maintainToobar.more)

        mBinding.maintainRv.adapter = mAdapter
        mBinding.maintainRv.layoutManager=LinearLayoutManager(this)

    }
    override fun initListener() {
        mBinding.maintainToobar.back.setOnClickListener {
            finish()
        }
        mViewModel.mPollingState.observeWithLifecycle(this){
            when(it){
                Empty -> {}
                is Failed -> {
                    ToastUtils.showLong(this,it.message)
                }
                Loading ->{}
                Success ->{
                    mAdapter.setData(mViewModel.mPollingList)

                }
            }
        }



    }
    override fun initData() {

        mViewModel.getPollingList()

    }



}